package com.scwatch.common.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 创建wowza
 */
public class CreateWowza {

//    //获取列表
//    public String Acquisition(String url) {
//        BufferedReader in = null;
//        StringBuffer sb = null;
//        try {
//            URL al = new URL(url);
//            in = new BufferedReader(new InputStreamReader(al.openStream()));
//
//            sb = new StringBuffer();
//            String inputLine;
//
//            while ((inputLine = in.readLine()) != null)
//                sb.append(inputLine);
//            System.out.println(inputLine);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                if (in != null) {
//                    in.close();
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//        return sb.toString();
//    }

    //创建列表
    public static void Create(String targetURL, String input) {
        try {
            URL targetUrl = new URL(targetURL);
            HttpURLConnection httpConnection = (HttpURLConnection) targetUrl.openConnection();
            httpConnection.setDoOutput(true);
            httpConnection.setRequestMethod("POST");
            httpConnection.setRequestProperty("Content-Type", "application/json; charset=utf-8");

            OutputStream outputStream = httpConnection.getOutputStream();
            outputStream.write(input.getBytes());
            outputStream.flush();

            if (httpConnection.getResponseCode() != 201) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + httpConnection.getResponseCode());
            }

            BufferedReader responseBuffer = new BufferedReader(new InputStreamReader(
                    (httpConnection.getInputStream())));


            httpConnection.disconnect();

        } catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }
    }
}
